<template>
  <vab-dialog v-model="isShowDialog" :close-on-click-modal="true" show-fullscreen width="80%">
    <template #default>
      <CommonForm
        ref="commonFormRef"
        v-model="form"
        v-loading="formLoading"
        :layout-config="layoutConfig"
        :option="option"
        @on-cancel="onHandleCancel"
      />
    </template>
  </vab-dialog>
</template>

<script>
import CommonForm from "@/plugins/form/CommonForm.vue";
import VabDialog from "@/plugins/VabDialog/index.vue";
import { TableColumnOrFormTypeEnum } from "@/plugins/commonType.enum";
import { getRequest } from "@/api/mains";
export default defineComponent({
  name: "MessageDetail",
  components: {
    CommonForm,
    VabDialog
  },
  emits: { "on-success": null },
  setup(props, { expose }) {
    const state = reactive({
      isShowDialog: false,
      formLoading: false,
      layoutConfig: {
        //form组件布局
        column: 2
      }
    });

    const form = ref({});
    const option = {
      column: [
        {
          label: "标题",
          prop: "title",
          type: TableColumnOrFormTypeEnum.INPUT
        },
        {
          label: "发送人",
          prop: "sendername",
          type: TableColumnOrFormTypeEnum.INPUT,
          placeholder: "请收入发送人"
        },
        {
          label: "发送时间",
          prop: "sendtime",
          type: TableColumnOrFormTypeEnum.DATE
        },
        {
          label: "接收人",
          prop: "receivername",
          type: TableColumnOrFormTypeEnum.INPUT,
          placeholder: "请输入接收人"
        },
        {
          label: "接收时间",
          prop: "receivetime",
          type: TableColumnOrFormTypeEnum.DATE
        },
        {
          label: "处理时间",
          prop: "dealtime",
          type: TableColumnOrFormTypeEnum.DATE
        },
        {
          label: "处理结果",
          prop: "dealresult",
          type: TableColumnOrFormTypeEnum.TEXTAREA,
          expand: 2
        }
      ],
      formConfig: {
        title: "消息查看",
        isInModal: true,
        disabled: true
      },
      btnsConfig: {
        save: {
          isShow: false
        }
      },
      rules: {}
    };
    const showDialog = async row => {
      state.formLoading = true;
      state.isShowDialog = true;
      if (row) {
        const res = await getRequest(`system/message/getAndRead/${row.id}`);
        form.value = res.data;
      } else {
        form.value = {};
      }
      state.formLoading = false;
    };

    const onHandleCancel = () => {
      state.isShowDialog = false;
    };

    expose({ showDialog });
    return {
      ...toRefs(state),
      form,
      option,
      onHandleCancel
    };
  }
});
</script>
